<extend name="Public:main" />
<block name="title">修改昵称</block>
<block name="body">
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
    <div class="nav_top flex">
        <a  href="javascript:void(0)"  onclick="window.history.go(-1)">
            <i></i>
        </a>
        <div class="flex1">
            修改昵称
        </div>
        <a  href="javascript:void(0)">
          
        </a>
    </div>
    <div style="height: 0.44rem;"></div>
    <div class="login">
        <div>
            <label>昵称</label>
            <input type="hidden" name="memberId" value="{$memberId}">
            <input style="text-align: right;" type="text" name="nickname" maxlength="15" placeholder="输入昵称" value="{$nickname}">
        </div>
    </div>
    <a class="login_btn" href="javascript:void(0)" ng-click="sub()">
        确 认
    </a>
</body>
<block name="custom_js">
    <script>
        var app = getApp('myApp', []);
        app.controller('Ctrl', function ($scope, $http) {
            $scope.sub=function () {
                $http({
                    method:'POST',
                    data:{
                        "memberId" : $("input[name='memberId']").val(),
                        "nickname" : $("input[name='nickname']").val(),
                    },
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                    transformRequest: function(obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    },
                    url: "/index.php/Home/Member/setNickName"
                }).then(function successCallback(response) {
                    if(response.data.code==0){
                        layer.msg(response.data.data);
                        setTimeout(function () {
                            window.location.href = '/index.php/Home/Member/index';
                        }, 1000);
                    }else {
                        layer.msg(response.data.msg)
                    }
                }, function errorCallback(response) {
                    errorHandle(response);
                });
            }
        });
    </script>
</block>
</block>